// 当前模块：所有的API进行统一管理
import request from './request'
import mockRequest from './mockAjax'

// 三级联动的接口
// GET  /api/product/getBaseCategoryList  无参数

export const reqCategoryList = () => {
    // 发请求:axios 发请求返回结果为Promise对象
    return request({
        url: '/product/getBaseCategoryList',
        method: 'get'
    })
}
//切记：当前函数执行需要把服务器返回结果返回

// 获取banner(Home首页轮播图接口)
export const reqGetBannerList = () => mockRequest.get('/banner')

//获取floor数据
export const reqFloorList = () => mockRequest.get('/floor')

//获取搜索search数据 地址：/api/list  POST  带参数
// {
//     "category3Id": "61",
//     "categoryName": "手机",
//     "keyword": "小米",
//     "order": "1:desc",
//     "pageNo": 1,
//     "pageSize": 10,
//     "props": ["1:1700-2799:价格", "2:6.65-6.74英寸:屏幕尺寸"],
//     "trademark": "4:小米"
// }
    //当前函数需不需要接收外部传递参数：需要
    //当前这个接口，给服务器传递参数params，至少是一个空对象  reqGetSearchInfo({})
export const reqGetSearchInfo = (params) => request({url: "/list",method: "post",data: params})
// export const reqGetSearchInfo = (params) => {
//     return request({
//         url: "/list",
//         method: "post",
//         data: params
//     })
// }

//获取商品详情detail数据
// export const reqGoodsInfo = (skuId) => request.get(`/api/item/${skuId}`)
export const reqGoodsInfo = (skuId) => {
    return request({
        url: `/item/${skuId}`,
        method: "get"
    })
}

//将产品添加到购物车中（获取更新某一个产品的个数）   /api/cart/addToCart/{ skuId }/{ skuNum }
export const reqAddOrUpdateShopCart = (skuId, skuNum) => {
    return request({
        url: `/cart/addToCart/${skuId}/${skuNum}`,
        method: 'post'
    })
}

//获取购物车列表数据接口  /api/cart/cartList
export const reqCartList = () => request({url:'/cart/cartList', method: 'get'})

//删除购物车产品的接口    /api/cart/deleteCart/{skuId}
export const reqDeleteCartById = (skuId) => request({url: `/cart/deleteCart/${skuId}`,method:'delete'})

//修改商品的选中状态  /api/cart/checkCart/{skuId}/{isChecked}
export const reqUpdateCheckedById = (skuId, isChecked) => request({url:`/cart/checkCart/${skuId}/${isChecked}`,method:'get'})

//获取验证码   /api/user/passport/sendCode/phone  get
export const reqGetCode = (phone) => request({url:`/user/passport/sendCode/${phone}`,method:'get'})

//注册接口 /api/user/passport/register  post   phone\code\password
export const reqUserRegister = (data) => request({url:'/user/passport/register',method:'post',data})

//登录  /api/user/passport/login   post   phone\password
//地址中没有 phone和password的字样，带个data
export const reqUserLogin = (data) => request({url:'/user/passport/login', method:'post', data})

//获取用户的信息【需要带着用户的token向服务器要用户信息】   /api/user/passport/auth/getUserInfo   get
//接口中没有关于token的字符串，通过请求头携带过去
export const reqUserInfo = () => request({url:'/user/passport/auth/getUserInfo', method: 'get'})

//退出登录   /api/user/passport/logout  get
export const reqLogout = () => request({url:'/user/passport/logout', method:'get'})

//获取用户地址信息   /api/user/userAddress/auth/findUserAddressList   get
export const reqAddressInfo = () => request({url:'/user/userAddress/auth/findUserAddressList', method:'get'})

//获取订单交易页信息 --商品清单  /api/order/auth/trade  get
export const reqOrderInfo = () => request({url:'/order/auth/trade', method: 'get'})

//提交订单的接口   /api/order/auth/submitOrder?tradeNo={tradeNo}   post   tradeNo在接口地址中通过?拼接，通过query带，其余参数data带
export const reqSubmitOrder = (tradeNo, data) => request({url:`/order/auth/submitOrder?tradeNo=${tradeNo}`,method:'post',data})

//获取订单支付信息    /api/payment/weixin/createNative/{orderId}  get
export const reqPayInfo = (orderId) => request({url:`/payment/weixin/createNative/${orderId}`,method:'get'})

//查询支付订单状态  /api/payment/weixin/queryPayStatus/{orderId}  get
export const reqPayStatus = (orderId) => request({url:`/payment/weixin/queryPayStatus/${orderId}`,method:'get'})

//获取个人中心的订单列表  /api/order/auth/{page}/{limit}  get   page\limit
export const reqMyOrderList = (page, limit) => request({url:`/order/auth/${page}/${limit}`, method:'get'})
